﻿using TrueSync;
using UnityEngine;

namespace HEFramework
{
    public static class RecoverComponentSystem
    {
        [EntitySystem]
        public class RecoverComponentAwakeSystem : AwakeSystem<RecoverComponent>
        {
            protected override void Awake(RecoverComponent _self)
            {
                _self.Reset_Recover_Time();
            }
        }


        [EntitySystem]
        public class RecoverComponentUpdateSystem : UpdateSystem<RecoverComponent>
        {
            protected override void Update(RecoverComponent _self)
            {
                FP deltaTime = Time.deltaTime;

                _self.Time -= deltaTime;
                if (_self.Time <= 0)
                {
                    var ac = _self.GetParentChild<AttributeComponent>();
                    if (ac == null)
                    {
                        return;
                    }

                    ac.OnHM(ac.REC_HP.Value, 0, false);
                    ac.OnHM(0, ac.REC_MP.Value, false);
                    _self.Reset_Recover_Time();
                }
            }
        }

        public static void Reset_Recover_Time(this RecoverComponent _self)
        {
            _self.Time = 1;
        }
    }
}